home *** CD-ROM | disk | FTP | other *** search
- Path: HOPPER.ACM.ORG!news
- From: varnk@e62.diebold.com (Ken Varn)
- Newsgroups: comp.lang.c++
- Subject: Re: strstream destruction
- Date: 3 Apr 1996 13:11:16 GMT
- Organization: Diebold
- Message-ID: <4jttdk$i6v@HOPPER.ACM.ORG>
- References: <315AD92C.726D@itd.ssb.com> <4jhgt0$17f@piper.logicon.com> <4joujt$72p@lib104.its.rpi.edu>
- NNTP-Posting-Host: 199.218.232.47
- Mime-Version: 1.0
- Content-Type: Text/Plain; charset=US-ASCII
- X-Newsreader: WinVN 0.99.7
-
- In article <4joujt$72p@lib104.its.rpi.edu>, floydb1@lib104.its.rpi.edu
- says...
- />
- />
- />This works for me:
- />
- />String StrStrFunc ( void ) // some function using strstream
- />{
- /> ostrstream a_stream ; //
- /> String a_string ; // a 'string' class (char *)
- />
- /> a_stream << a_variable // any type
- /> << ends ; // null terminate string
- />
- /> a_string = a_stream.str() ; // get the buffer
- />
- /> a_stream.freeze(0) ; // unfreeze buffer
- />
- /> return ( a_string ) ; // out of scope, deletes string
- /> // returns copy
- />}
-
- Just curious about this as it indirecly applies to something that I am
- wondering about. If a_stream is declared globally or as a data member of a
- class, and you were to perform this function with it, would its internal
- buffer get dynamically reallocated on each call, or would the object maintain
- its own internal buffer and increase or decrease its size as needed (see
- below)?
-
- ostrstream a_stream;
-
- String StrStrFunc ( void ) // some function using strstream
- {
- String a_string ; // a 'string' class (char *)
-
- a_stream << a_variable // any type
- << ends ; // null terminate string
-
- a_string = a_stream.str() ; // get the buffer
-
- a_stream.freeze(0) ; // unfreeze buffer
-
- return ( a_string ) ; // out of scope, deletes string
- // returns copy
- }
-
-